package com.zelin.manager.web;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.alibaba.dubbo.config.annotation.Reference;
import com.zelin.entity.SellerEntity;
import com.zelin.sellergoods.service.SellerService;
import com.zelin.utils.PageUtils;
import com.zelin.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;




/**
 * 
 *
 * @author WF
 * @email 2568783935@qq.com
 * @date 2021-07-23 21:10:35
 */
@RestController
@RequestMapping("/seller")
public class SellerController {
    @Reference(timeout = 5000)
    private SellerService sellerService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = sellerService.queryPage(params);
        List<SellerEntity> list = (List<SellerEntity>) page.getList();
        //1. 收集新的集合，没有经过审核的数据
        List<SellerEntity> collect =
                list.stream().filter(f -> f.getStatus().equals("0"))
                    .collect(Collectors.toList());
        //2. 重新将数据设置回当前页面
        page.setList(collect);
        //3. 返回
        return R.ok().put("page", page);
    }

    /**
     * 功能: 商家审核
     * 参数:
     * 返回值:
     * 时间: 2021/7/27 15:32
     */
    @RequestMapping("/updateStatus/{sellerId}/{status}")
    public R updateStatus(@PathVariable String sellerId,@PathVariable String status){
        sellerService.updateStatus(sellerId,status);
        return R.ok();
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{sellerId}")
    //@RequiresPermissions("manager:seller:info")
    public R info(@PathVariable("sellerId") String sellerId){
		SellerEntity seller = sellerService.getById(sellerId);

        return R.ok().put("seller", seller);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("manager:seller:save")
    public R save(@RequestBody SellerEntity seller){
		sellerService.save(seller);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("manager:seller:update")
    public R update(@RequestBody SellerEntity seller){
		sellerService.updateById(seller);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("manager:seller:delete")
    public R delete(@RequestBody String[] sellerIds){
		sellerService.removeByIds(Arrays.asList(sellerIds));

        return R.ok();
    }

}
